import cv2

# 创建
cv2.namedWindow('newWin', cv2.WINDOW_NORMAL)
cv2.imshow('newWin', 0)

# 第二个参数 0 IMREAD_GRAYSCALE，  1 IMREAD_COLOR default
img = cv2.imread('E:\\yunLiu\\20231030.png', 0)

# 窗口中显示图片
cv2.resizeWindow('newWin', width=800, height=600)

cv2.imshow('newWin', img )

"""
# 等待按键事件
key = cv2.waitKey(0)
print(key)
print('q')

# 获取ascii
print(ord('q'))

if(key == ord('q')) :
    print('1111')
    exit()


# 销毁所有窗口
cv2.destroyWindow('newWin')
"""

while True:
    key = cv2.waitKey(0)

    if(key & 0xFF == ord('q')):
        # exit()
        # 否则会有死循环
        break
    elif(key & 0xFF == ord('s')):
        # 按照读取后的格式保存，上面是灰度图，这里也是
        cv2.imwrite('E:\\yunLiu\\20231030_c.png', img)
    else:
        print(key)

cv2.destroyWindow('newWin')